from selenium import webdriver
import unittest
from selenium.webdriver.common.by import By
import traceback
from time import sleep
class Login_002(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        cls.driver = webdriver.Chrome()
        cls.driver.get('http://192.168.4.67/index.php/Home/user/login.html')
        cls.driver.maximize_window()
    def setUp(self) -> None:
        pass
    def tearDown(self) -> None:
        self.driver.refresh()
    @classmethod
    def tearDownClass(cls) -> None:
        cls.driver.quit()

    def test_z001(self):
        self.driver.find_element(By.ID,'username').send_keys('13800138006')
        self.driver.find_element(By.ID,'password').send_keys('123456')
        self.driver.find_element(By.ID,'verify_code').send_keys('1111')
        self.driver.find_element(By.NAME,'sbtbutton').click()
        sleep(2)
        expect = '安全退出'
        rel = self.driver.find_element(By.LINK_TEXT, '安全退出').text
        if expect == rel:
            print('第一条用例OK')
        else:
            print('第一条用例NG')
    def test_a002(self):
        self.driver.find_element(By.ID,'username').send_keys('1380013800')
        self.driver.find_element(By.ID,'password').send_keys('123456')
        self.driver.find_element(By.ID,'verify_code').send_keys('1111')
        self.driver.find_element(By.NAME,'sbtbutton').click()
        sleep(2)
        expect = '账号格式不匹配!'
        rel = self.driver.find_element(By.CSS_SELECTOR, '[class="layui-layer-content layui-layer-padding"]').text
        if expect == rel:
            print('第二条用例OK')
        else:
            print('第二条用例NG')
        sleep(2)
    def test_a003(self):
        self.driver.find_element(By.ID,'username').send_keys('13800138006')
        self.driver.find_element(By.ID,'password').send_keys('12345')
        self.driver.find_element(By.ID,'verify_code').send_keys('1111')
        self.driver.find_element(By.NAME,'sbtbutton').click()
        sleep(3)
        expect = '密码错误!'
        rel = self.driver.find_element(By.CSS_SELECTOR, '[class="layui-layer-content layui-layer-padding"]').text
        if expect == rel:
            print('第三条用例OK')
        else:
            print('第三条用例NG')
        sleep(2)
if __name__ == '__main__':
    unittest.main()
